import {createApp} from 'vue';
import {createPinia} from 'pinia';

import App from './App.vue';
import router from './router';
import i18n from './i18n.js';
import 'amfe-flexible/index.js';
import 'vant/es/toast/style';
import 'vant/es/notify/style';
import 'vant/es/dialog/style';
import '@/assets/styles/initialize.css';
import '@/assets/styles/base.css';
import req from '@/libs/req';
import {showToast} from 'vant';

const app = createApp(App);

app.use(createPinia());
app.use(router);
app.use(i18n);

router.beforeEach((to, from) => {
    const token = req.defaults.headers.token;
    if (!token && (to.path !== '/' && to.path !== '/home')) return showToast('请先连接钱包');

    if (to.meta.title) {
        document.title = to.meta.title;
    }
});

app.mount('#app');
